import scala.util.Random

class MusicPlayer {
  var musicList: List[String] = List()
  var currentMusic: Option[String] = None
  var playMode: String = "Sequential"

  def addMusic(music: String): Unit = {
    musicList = musicList :+ music
    println(s"音乐 $music 已添加到播放列表")
  }

  def removeMusic(music: String): Unit = {
    musicList = musicList.filterNot(_ == music)
    println(s"音乐 $music 已从播放列表中移除")
  }

  def setPlayMode(mode: String): Unit = {
    playMode = mode
    println(s"播放模式已设置为 $mode 模式")
  }

  def play(): Unit = {
    playMode match {
      case "Sequential" =>
        currentMusic = musicList.headOption
      case "Shuffle" =>
        currentMusic = Random.shuffle(musicList).headOption
      case "Repeat" =>
        currentMusic = currentMusic.orElse(musicList.headOption)
    }

    currentMusic match {
      case Some(music) =>
        println(s"正在播放：$music")
      case None =>
        println("播放列表为空，请添加音乐后再播放")
    }
  }

  def displayPlaylist(): Unit = {
    println("播放列表：")
    musicList.foreach(println)
  }
}
/*
// 示例用法
object MusicPlayerExample {
  def main(args: Array[String]): Unit = {
    val player = new MusicPlayer

    player.addMusic("Song 1")
    player.addMusic("Song 2")
    player.addMusic("Song 3")

    player.displayPlaylist()

    player.setPlayMode("Shuffle")
    player.play()

    player.setPlayMode("Sequential")
    player.play()

    player.removeMusic("Song 2")
    player.displayPlaylist()

    player.play()
  }
}
*/
